﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using mendian;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.固定资产
{
    public class 固定资产Service
    {
        /// <summary>
        /// 取得所有资产类别
        /// </summary>
        /// <returns></returns>
        public static List<AssertTypeDTO> getAssertTypeDTO()
        {
            try
            {
                return FunctionHelper.JsonDeserialization<List<AssertTypeDTO>>(
                    RestCall.httpGetMethod(URL.接口url + "/assert/getAssertTypeDTOAll"));
            }
            catch
            {
                return new List<AssertTypeDTO>();
            }
        }
        /// <summary>
        /// 取得所有供应商
        /// </summary>
        /// <returns></returns>
        public static List<AssertVendorDTO> getAssertVendorDTOs()
        {
            try
            {
                return FunctionHelper.JsonDeserialization<List<AssertVendorDTO>>(
                    RestCall.httpGetMethod(URL.接口url + "/assert/getAssertVendorDTOAll"));
            }
            catch
            {
                return new List<AssertVendorDTO>();
            }
        }
        /// <summary>
        /// 取得固定资产一览
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<AssetsDTO> getAssets(String pageIndex,String pageSize)
        {
            try
            {
                return FunctionHelper.JsonDeserialization<List<AssetsDTO>>(
                    RestCall.httpGetMethod(URL.接口url + "/assert/getAssetsDTOAll?pageIndex=" + pageIndex + "&pageSize=" + pageSize));
            }
            catch
            {
                return new List<AssetsDTO>();
            }
        }
        /// <summary>
        /// 根据固定资产条码查找固定资产
        /// </summary>
        /// <param name="assertNo"></param>
        /// <returns></returns>
        public static AssetsDTO getAssetsDTOByAssertNo(String assertNo)
        {
            try
            {
                return FunctionHelper.JsonDeserialization<AssetsDTO>(
                    RestCall.httpGetMethod(URL.接口url + "/assert/getAssetsDTOByAssertNo?assertNo=" + assertNo));
            }
            catch
            {
                return new AssetsDTO();
            }
        }
        /// <summary>
        /// 扫码取员工
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <returns></returns>
        public static Employee getEmployeeShortDTOByMnemonic(String mnemonic)
        {
            try
            {
                return FunctionHelper.JsonDeserialization<Employee>(
                    RestCall.httpGetMethod(URL.接口url + "/assert/getEmployeeShortDTOByMnemonic?mnemonic=" + mnemonic));
            }
            catch
            {
                return new Employee();
            }
        }
        /// <summary>
        /// 取得最新资产卡片编号
        /// </summary>
        /// <returns></returns>
        public static String getNewAssetsNo()
        {
            try
            {
                return RestCall.PostHttp(URL.接口url + "/assert/getNewAssetsNo", "");
            }
            catch
            {
                return String.Empty;
            }
        }
        /// <summary>
        /// 创建固定资产卡片
        /// </summary>
        /// <param name="assetsDTO"></param>
        /// <returns></returns>
        public static Boolean createAssetsDTO(AssetsDTO assetsDTO)
        {
            try
            {
                RestCall.PostHttp(URL.接口url + "/assert/createAssetsDTO", FunctionHelper.JsonSerialization(assetsDTO));
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 创建供应商
        /// </summary>
        /// <param name="vendorName">供应商名称</param>
        /// <param name="contract">联系人</param>
        /// <param name="mobile">联系方式</param>
        /// <param name="email">email</param>
        /// <returns></returns>
        public static AssertVendorDTO createAssertVendorDTO(String vendorName, String contract, String mobile, String email)
        {
            try
            {
                return FunctionHelper.JsonDeserialization<AssertVendorDTO>(
                    RestCall.httpGetMethod(URL.接口url + "/assert/createAssertVendorDTO?vendorName=" + vendorName +
                    "&contract=" + contract +
                    "&mobile=" + mobile +
                    "&email=" + email));
            }
            catch
            {
                return new AssertVendorDTO();
            }
        }
        /// <summary>
        /// 创建资产类别
        /// </summary>
        /// <param name="name">资产名称</param>
        /// <param name="assertType">资产卡片类型</param>
        /// <param name="band">品牌</param>
        /// <param name="usage">用途</param>
        /// <param name="ofd"></param>
        /// <returns></returns>
        public static Boolean createAssertTypeDTO(String name,String assertType,String band,String usage, OpenFileDialog ofd)
        {
            try
            {
                FileService.UploadRequest(
                    URL.接口url + "/assert/createAssertTypeDTO?name=" + name +
                    "&assertType=" + assertType +
                    "&band=" + band +
                    "&usage=" + usage,
                    ofd.FileName,
                    Path.GetFileName(ofd.FileName),
                    "multipartFile");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
    /// <summary>
    /// 固定资产列表
    /// </summary>
    public class AssetsDTO
    {
        public String assertNo { get; set; }
        /**
         * 资产类别
         */
        public String assertTypeId { get; set; }    //  资产类别id
        public String name { get; set; }   //  资产名称
        public String assertType { get; set; } //  资产卡片类型
        public String band { get; set; }   //  品牌
        public String usage { get; set; }  //  用途
        public String docUrl { get; set; }  //  文档路径
        /**
         * 资产归属
         */
        public String ownerShipId { get; set; } //  归属人员id
        public String ownerShip { get; set; } //  归属人员
        /**
         * 供应商信息
         */
        public String vendorId { get; set; }   //  供应商ID
        public String vendorName { get; set; }  //  供应商名称
        public String contract { get; set; }  //  联系人
        public String mobile { get; set; } //  联系方式
        public String email { get; set; }   //  email
        /**
         * 设备其他信息
         */
        public String location { get; set; }   //  位置
        public Boolean inUse { get; set; } //  在用
        public Boolean discard { get; set; }   //  报废
        public DateTime createDate { get; set; }//创建时间

        public AssetsDTO()
        {

        }
    }
    /// <summary>
    /// 供应商
    /// </summary>
    public class AssertVendorDTO
    {
        public String vendorId { get; set; }    //  供应商ID
        public String vendorName { get; set; }   //  供应商名称
        public String contract { get; set; }   //  联系人
        public String mobile { get; set; }//  联系方式
        public String email { get; set; }  //  email
        public DateTime createDate { get; set; }//创建时间

        public AssertVendorDTO()
        {

        }
    }
    /// <summary>
    /// 资产类别
    /// </summary>
    public class AssertTypeDTO
    {
        public String vendorId { get; set; }   //  供应商ID
        public String vendorName { get; set; }    //  供应商名称
        public String contract { get; set; }   //  联系人
        public String mobile { get; set; }  //  联系方式
        public String email { get; set; }   //  email
        public String docUrl { get; set; }   //  文档路径
        public DateTime createDate { get; set; }//创建时间

        public AssertTypeDTO()
        {

        }
    }
    /// <summary>
    /// 员工
    /// </summary>
    public class Employee
    {
        public String id { get; set; }
        public String name { get; set; }
        public Employee()
        {
        }
    }
}
